<?php

use Nette\Security as NS,
        Nette\Application\UI;


/**
 * Sign in/out presenters.
 *
 * @author     John Doe
 * @package    MyApplication
 */
class SignPresenter extends BasePresenter
{


	/**
	 * Sign in form component factory.
	 * @return Nette\Application\UI\Form
	 */
        public function renderIn()
	{
              #  $this->template->facebookLoginUrl = $this->context->facebook->getLoginUrl();
	}


	protected function createComponentSignInForm()
	{
		$form = new UI\Form;
		$form->addText('username', 'Uživatelské jmeno:')
			->setRequired('Prosím zadejte své uživatelské jméno.');
		$form->addPassword('heslo', 'Heslo:')
			->setRequired('Prosím zadejte své heslo.');
		$form->addCheckbox('zapamatovat', 'Zapamatovat na tomto PC.');
		$form->addSubmit('send', 'Přihlásit');
		$form->onSuccess[] = callback($this, 'signInFormSubmitted');
		return $form;
	}
	public function signInFormSubmitted($form)
	{
		try {
			$values = $form->getValues();
			if ($values->zapamatovat) {
				$this->getUser()->setExpiration('+ 7 days', TRUE);
			} else {
				$this->getUser()->setExpiration('+ 20 minutes', TRUE);
			}
			$this->getUser()->login($values->username, $values->heslo);
			$this->redirect('Admin:');

		} catch (NS\AuthenticationException $e) {
			$form->addError($e->getMessage());
		}
                //$this->error("neff");
                $this->redirect('Admin:');
	}

}
